package com.byCreation.t_globe;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONObject;

import com.aretha.slidemenu.SlideMenu;
import com.byCreatetion.adabter.CardListAdapter;
import com.byCreatetion.adabter.GridViewAdapter;
import com.byCreation.Control.Control;
import com.byCreation.Control.SliderMenuLeft;
import com.byCreation.Profile.CompareActivity;
import com.byCreation.Profile.MyBookmarkActivity;
import com.byCreation.Profile.MyDiscountActivity;
import com.byCreation.Profile.MyHistoryActivity;
import com.byCreation.Profile.MyNoteActivity;
import com.byCreation.Profile.MySettingActivity;
import com.byCreation.Profile.MyprofileActivity;
import com.byCreation.Profile.NoticeActivity;
import com.byCreation.Profile.TglobeAppActivity;
import com.byCreation.t_globe.R;
import com.google.analytics.tracking.android.EasyTracker;
import com.google.analytics.tracking.android.GoogleAnalytics;
import com.google.analytics.tracking.android.Tracker;
import com.google.android.gms.maps.model.LatLng;
import com.squareup.picasso.Picasso;



import Myclass.ConnectInternet;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.StrictMode;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.Animation.AnimationListener;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.FrameLayout;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView.OnItemClickListener;

public class CardActivity extends BaseSlideMenuActivity implements OnClickListener,OnItemClickListener,AnimationListener {

	// SliderMenu
	private SlideMenu mSlideMenu;

	
	// ==================ListView======================
		private ListView list_view_card;
		private CardListAdapter adapter;
		public  ArrayList<HashMap<String, Object>> MyArrList;
		private HashMap<String, Object> map = new HashMap<String, Object>();
		private ProgressDialog mProgressDialog;

		private  Animation anim_menu_show,anim_menu_hide;
		private FrameLayout lay_menu;

			
			
		//=======menu down
		private FrameLayout lay_filter,lay_search,lay_ok_filter,lay_search_n;
		public static LinearLayout lay_cardmenu_down;
		private  Animation anim_downmenu_in,anim_downmenu_out,anim_downmenu_hide;
		public static boolean isMenuShow=false;
			
			//====Filter GridVeiw
			
		private GridView gridView;
		public  ArrayList<HashMap<String, Object>> MyArrList_grid;
		private HashMap<String, Object> map_grid = new HashMap<String, Object>();
		private GridViewAdapter customGridAdapter;
			//====search
		public static LinearLayout lay_search_edittext;
		private FrameLayout lay_filter_n,lay_search_ok;
		public static FrameLayout lay_alpha;
	
	
	
		//map

		// ===============GoogleAnalytics==============
					private GoogleAnalytics mGaInstance;
					private Tracker mGaTracker;
					// =============================================
		// ===================================googleAnalytics=============================
				@Override
				public void onStart() {
					super.onStart();
					// The rest of your onStart() code.
					EasyTracker.getInstance().activityStart(this); // Add this method.
					mGaTracker.sendView("Card Screen");

				}

				@Override
				public void onStop() {
					super.onStop();
					// The rest of your onStop() code.
					EasyTracker.getInstance().activityStop(this); // Add this method.

				}

				// ================================================================
		
	
	@Override
	public void onContentChanged() {
		super.onContentChanged();
		Log.e("Test", "SlideMenuAttribute");

		setSlideRole(R.layout.activity_card);
		setSlideRole(R.layout.layout_primary_menu);
		setSlideRole(R.layout.fagment_profile);
		SetSliderMenu();

		
		// =============================GoogleAnalytics=========================
		mGaInstance = GoogleAnalytics.getInstance(this);
		mGaTracker = mGaInstance.getTracker(Control.IDGoogleanalytics);
		
		if (android.os.Build.VERSION.SDK_INT > 9) {
			StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
					.permitAll().build();
			StrictMode.setThreadPolicy(policy);
		}
		
		
		
		
		SetView();
		SetViewProfile();

		
		setGridView();
		

	}
	
	private void SetSliderMenu() {
		// TODO Auto-generated method stub
		mSlideMenu = getSlideMenu();

		mSlideMenu.setEdgeSlideEnable(true);
		mSlideMenu.setEdgetSlideWidth(Control.setEdgetSlideWidth);
		Display display = getWindowManager().getDefaultDisplay();
		int width = display.getWidth(); // deprecated
		int height = display.getHeight(); // deprecated

		
		RelativeLayout rl = (RelativeLayout) findViewById(R.id.R1);
		RelativeLayout r2 = (RelativeLayout) findViewById(R.id.R2);

		rl.getLayoutParams().width = width - 100;
		r2.getLayoutParams().width = width - 100;
		slide=new SliderMenuLeft(this,true,mSlideMenu);
		
	}
	
	//Profile
	private ImageView img_profile_menu1,img_profile_menu2,img_profile_menu3,
	img_profile_menu4,img_profile_menu5,img_profile_menu6,img_profile_menu7,
	img_profile_menu8,img_profile_menu9,img_user;
	private LinearLayout txt_next,txt_register;
	private FrameLayout Laylogin;
	
	private void SetViewProfile() {
		// TODO Auto-generated method stub
		
		
		Laylogin=(FrameLayout)findViewById(R.id.Laylogin);
		if(!Control.Loginstatus)
			Laylogin.setVisibility(View.VISIBLE);
		
		
		//=======menu
		img_profile_menu1=(ImageView)findViewById(R.id.img_profile_menu1);
		img_profile_menu2=(ImageView)findViewById(R.id.img_profile_menu2);
		img_profile_menu3=(ImageView)findViewById(R.id.img_profile_menu3);
		img_profile_menu4=(ImageView)findViewById(R.id.img_profile_menu4);
		img_profile_menu5=(ImageView)findViewById(R.id.img_profile_menu5);
		img_profile_menu6=(ImageView)findViewById(R.id.img_profile_menu6);
		img_profile_menu7=(ImageView)findViewById(R.id.img_profile_menu7);
		img_profile_menu8=(ImageView)findViewById(R.id.img_profile_menu8);
		img_profile_menu9=(ImageView)findViewById(R.id.img_profile_menu9);
		
		img_user=(ImageView)findViewById(R.id.img_user);
		img_user.setOnClickListener(this);
		
		

		TextView txt_username=(TextView) findViewById(R.id.txt_username);
		txt_username.setText(Control.UserName);
		
		
		
		try {
				
			
			
			Log.e("Picasso", "=========Picasso() ==========");
			
			if(Control.Img_profile.equals(""))
			{
				img_user.setImageResource(R.drawable.btn_menu_top_righ);

			}
			else
			{
				Bitmap myBitmap = BitmapFactory.decodeFile(Control.Img_profile_Path);
				img_user.setImageBitmap(myBitmap);
			}
			
			
			
			} catch (Exception e) {
				img_user.setImageResource(R.drawable.btn_menu_top_righ);
			}
		
		
		img_profile_menu1.setOnClickListener(this);
		img_profile_menu2.setOnClickListener(this);
		img_profile_menu3.setOnClickListener(this);
		img_profile_menu4.setOnClickListener(this);
		img_profile_menu5.setOnClickListener(this);
		img_profile_menu6.setOnClickListener(this);
		img_profile_menu7.setOnClickListener(this);
		img_profile_menu8.setOnClickListener(this);
		img_profile_menu9.setOnClickListener(this);

		
		
		//=========Login
		txt_next=(LinearLayout)findViewById(R.id.txt_next);
		txt_next.setOnClickListener(this);
		
		txt_register=(LinearLayout)findViewById(R.id.txt_register);
		txt_register.setOnClickListener(this);
		
		
		ImageView img_tglobe_login=(ImageView)findViewById(R.id.img_tglobe_login);
		img_tglobe_login.setOnClickListener(this);
		
		ImageView img_facebook =(ImageView)findViewById(R.id.img_facebook);
		img_facebook.setOnClickListener(this);
		
		
		
	}

	
	
	
	
	
	@Override
	protected void onRestart() {
		// TODO Auto-generated method stub
		
		slide.ReSetMainMenu();
		
		super.onRestart();
	}
	
	
	
	
	
	
	
	
	SliderMenuLeft slide;
	private void SetView() {
		// ===========top menu
		ImageView img_mainmenu = (ImageView)findViewById(R.id.img_mainmenu);
		img_mainmenu.setOnClickListener(this);
		ImageView img_profile = (ImageView)findViewById(R.id.img_profile);
		img_profile.setOnClickListener(this);
		ImageView img_home = (ImageView)findViewById(R.id.img_home);
		img_home.setOnClickListener(this);
		
		
		
			try {
				
			
			
			Log.e("Picasso", "=========Picasso() ==========");
			
			if(Control.Img_profile.equals(""))
			{
				img_profile.setImageResource(R.drawable.btn_menu_top_righ);

			}
			else
			{
				Bitmap myBitmap = BitmapFactory.decodeFile(Control.Img_profile_Path);
				img_profile.setImageBitmap(myBitmap);
			}
			
			
			
			} catch (Exception e) {
				img_profile.setImageResource(R.drawable.btn_menu_top_righ);
			}		
		
		//anim
	
		anim_menu_show = AnimationUtils.loadAnimation(CardActivity.this, R.anim.anim_menu_show);
		anim_menu_hide = AnimationUtils.loadAnimation(CardActivity.this, R.anim.anim_menu_hide);
		anim_downmenu_hide= AnimationUtils.loadAnimation(CardActivity.this, R.anim.anim_downmenu_hide);
		anim_downmenu_hide.setAnimationListener(this);
		
		
		lay_menu=(FrameLayout)findViewById(R.id.lay_munu);
		
		//============LidtView
		
		list_view_card = (ListView)findViewById(R.id.list_view_card);
		CardActivity.this.setProgressBarIndeterminateVisibility(true);
		list_view_card.setOnItemClickListener(this);
		
//		//=========footer

		try {
		@SuppressWarnings("static-access")
		View footerView =  ((LayoutInflater)CardActivity.this.getSystemService(CardActivity.this.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.lay_footercard, null, false);
		list_view_card.addHeaderView(footerView, null, false);
		} catch (Exception e) {
			Log.e("TG", e.toString());
		}
		ScrollState();
		 
		 
		 
		//==========menu down
		 lay_filter=(FrameLayout)findViewById(R.id.lay_filter);
		 lay_filter.setOnClickListener(this);
		 lay_search=(FrameLayout)findViewById(R.id.lay_search);
		 lay_search.setOnClickListener(this);
		 lay_search_n=(FrameLayout)findViewById(R.id.lay_search_n);
		 lay_search_n.setOnClickListener(this);
		 lay_filter_n=(FrameLayout)findViewById(R.id.lay_filter_n);
		 lay_filter_n.setOnClickListener(this);
		 lay_search_ok=(FrameLayout)findViewById(R.id.lay_search_ok);
		 lay_search_ok.setOnClickListener(this);
		 
		 
		 
		 lay_ok_filter=(FrameLayout)findViewById(R.id.lay_ok_filter);
		 lay_ok_filter.setOnClickListener(this);
		 
		 
		 
		 lay_search_edittext=(LinearLayout)findViewById(R.id.lay_search_edittext);
		 lay_alpha=(FrameLayout)findViewById(R.id.lay_alpha);
		 lay_alpha.setOnClickListener(this);
		 lay_cardmenu_down=(LinearLayout)findViewById(R.id.lay_cardmenu_down);
		 anim_downmenu_in = AnimationUtils.loadAnimation(CardActivity.this, R.anim.anim_downmenu_show);
		 anim_downmenu_out= AnimationUtils.loadAnimation(CardActivity.this, R.anim.anim_downmenu_hide);
		 
		 
		 
		 //=====================ProgressDialog==========================
        mProgressDialog = new ProgressDialog(CardActivity.this);
        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);         
        mProgressDialog.setMessage("Loading......");                       
        mProgressDialog.setCancelable(false);  
		MyArrList = new ArrayList<HashMap<String, Object>>();

		
        if(new ConnectInternet(CardActivity.this).checkInternetConnection());
		new LoadCard().execute();

	}
	
	
	public void setGridView() {

		
			gridView = (GridView)findViewById(R.id.gridView1);
		if (MyArrList_grid == null)
			MyArrList_grid = new ArrayList<HashMap<String, Object>>();
		
	//	new LoadFilter().execute();
		
	}
	

	
	
	

	
	@Override
	public void onAnimationEnd(Animation an) {
		// TODO Auto-generated method stub
		/*if(an==anim_downmenu_hide&&Lay_bg_downmenu.getVisibility()==View.VISIBLE)
		{
			Log.e("TG", "onAnimationEnd");
			Lay_bg_downmenu.setVisibility(View.INVISIBLE);
		}*/
	}

	@Override
	public void onAnimationRepeat(Animation an) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onAnimationStart(Animation an) {
		// TODO Auto-generated method stub
		
	}
	
	
	
	
	
	@Override
	public void onItemClick(AdapterView<?> arg0, View v, int position, long arg3) {
		// TODO Auto-generated method stub
		
		position--;//Has header
		Log.e("TG", "ListCard Position="+position);

		try{
		Control.carddetail_id=MyArrList.get(position).get("card_id").toString();
		Control.carddetail_name=MyArrList.get(position).get("name").toString();
		
		Log.e("TG", "ListCard Position="+position);
		
		//CardActivity.this.finish();
		
		startActivity(new Intent(CardActivity.this,CardDetailActivity.class));
		overridePendingTransition (R.anim.fade_in, R.anim.fade_out);
		Toast.makeText(CardActivity.this,"Control.carddetail_id="+Control.carddetail_id, 900).show();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			Toast.makeText(CardActivity.this,e.toString(), 900).show();
			e.printStackTrace();
		}
		
		
	}
	
	
	
	

	@SuppressWarnings("deprecation")
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub

		if(v.getId()==R.id.img_profile)
		{
			mSlideMenu.open_R(true, true);

		}
		else
		if(v.getId()==R.id.img_mainmenu)
		{
			mSlideMenu.open_L(true, true);

		}
		 else if (v.getId() == R.id.img_home) {

			startActivity(new Intent(CardActivity.this,MainActivity.class));
			CardActivity.this.finish();

		}
		
		
		// ======Profile
				// //================Menu==============
				if (v.getId() == R.id.img_profile_menu1) {
					startActivity(new Intent(CardActivity.this, MyHistoryActivity.class));
				}
				if (v.getId() == R.id.img_profile_menu2) {
					startActivity(new Intent(CardActivity.this,
							MyBookmarkActivity.class));
				}
				if (v.getId() == R.id.img_profile_menu3) {
					startActivity(new Intent(CardActivity.this, MyNoteActivity.class));
				}
				if (v.getId() == R.id.img_profile_menu4) {
					// startActivity(new
					// Intent(MainActivity.this,MyCompareActivity.class));
					startActivity(new Intent(CardActivity.this, CompareActivity.class));

				}
				if (v.getId() == R.id.img_profile_menu5) {
					startActivity(new Intent(CardActivity.this, NoticeActivity.class));
				}
				if (v.getId() == R.id.img_profile_menu6) {
					startActivity(new Intent(CardActivity.this, TglobeAppActivity.class));
				}

				if (v.getId() == R.id.img_profile_menu7) {
					startActivity(new Intent(CardActivity.this,
							MyDiscountActivity.class));
				}
				if (v.getId() == R.id.img_profile_menu8) {
					startActivity(new Intent(CardActivity.this, MySettingActivity.class));
				}
				if (v.getId() == R.id.img_profile_menu9) {
					
					
					Control.Loginstatus=false;
					Control.UserName="";
					Control.UserPassword="";
					SharedPreferences sharedpreferences = getSharedPreferences("Tglobe", Context.MODE_PRIVATE);	

					Editor editor = sharedpreferences.edit();
					editor.putString("Username", Control.UserName);
					editor.putString("Password", Control.UserPassword);
					
					
					Log.e("tglobe","======Logout=======");

					Log.e("tglobe",sharedpreferences.getString("Username", ""));
					Log.e("tglobe",sharedpreferences.getString("Password", ""));
				
					
					CardActivity.this.finish();
					startActivity(new Intent(CardActivity.this, LoginActivity.class));
				}

				if (v.getId() == R.id.img_user) {

					startActivity(new Intent(CardActivity.this, MyprofileActivity.class));
				}

		
		

	}

	
	
	float Y_Down=0.0f;
	float Y_Move=0.0f;
	float Y_Up=0.0f;
	private int _firstVisibleItem=0,_visibleItemCount=0,_totalItemCount=0;
	public void ScrollState (){
		list_view_card.setOnScrollListener(new OnScrollListener() {

		
			
			public void onScroll(AbsListView view, int firstVisibleItem,
					int visibleItemCount, int totalItemCount) {
				// TODO Auto-generated method stu

				_visibleItemCount= visibleItemCount;
				_firstVisibleItem=firstVisibleItem;
				_totalItemCount=totalItemCount;
				
				if (firstVisibleItem + visibleItemCount >= totalItemCount) {

					
					
					
					
					ShowMenu();
					Log.e("TG","Show LoadMore");
				}
				//Log.e("TG","firstVisibleItem="+firstVisibleItem);

			}

			public void onScrollStateChanged(AbsListView view,int scrollState) {

				
				
				Log.e("TG", "Scroll state="+scrollState);
				
				if (scrollState == 0)
				{
					
					Log.e("TG", "scrolling stopped...");
					
					
				}
				
				if(_firstVisibleItem==0)
					{
						ShowMenu();
						Log.e("TG", "ShowMenu");
					}					

			}
		});
		
		
		
		//===========List touch
		list_view_card.setOnTouchListener(new OnTouchListener() {
			
	        public boolean onTouch(View v, MotionEvent event) {

	            if (event.getAction() == MotionEvent.ACTION_DOWN) {
	            	
	            	
	            	//Log.e("TG","y Down="+event.getY());
	            	Y_Down=event.getY();
	            }
	            
	            
	            if (event.getAction() == MotionEvent.ACTION_MOVE) {
	            	
	            	
	            	//Log.e("TG","y Move="+event.getY());
	            	Y_Move=event.getY();
	            		
	            }
	            
	            if(event.getAction() == MotionEvent.ACTION_UP)
	            {
	            	
	            	if(Y_Down-Y_Move>150&&lay_menu.getVisibility()==View.VISIBLE)
	            	{
	            		if (!(_firstVisibleItem + _visibleItemCount+1 >= _totalItemCount))
	            		HideMenu();
	            	}
	            	if(Y_Down-Y_Move<150&&lay_menu.getVisibility()==View.INVISIBLE)
	            	{
	            		ShowMenu();
	            	}	
	            	
	            }
	            return false;
	        }
		});  
		
		
		
		
		
	}
	
	
	
	private void ShowMenu() {
			// TODO Auto-generated method stub
				
				if(lay_menu.getVisibility()==View.INVISIBLE)
				{
					lay_menu.setVisibility(View.VISIBLE);
					lay_menu.startAnimation(anim_menu_show);
				}
			
			}
	private void HideMenu() {
				// TODO Auto-generated method stub
				
				if(lay_menu.getVisibility()==View.VISIBLE)
				{
					lay_menu.setVisibility(View.INVISIBLE);
					lay_menu.startAnimation(anim_menu_hide);
				}
			}

	
	
	public static String titlemap="";
	public static String longitude;
	public static String latitude;
					  
			
	ProgressBar progressBar1;
	class LoadCard extends AsyncTask<Object, Integer, Object> {

		private Boolean onCancelled=false;
		
		@Override
		protected void onCancelled() {
			// TODO Auto-generated method stub
		Log.e("globe", "onCancelled()");
		onCancelled=true;
			super.onCancelled();
		}

		@SuppressWarnings("null")
		@Override
		protected Object doInBackground(Object... params) {
			runOnUiThread(new Runnable() {
				  public void run() {
					
			    try {
						
			    	
			    	
			    	
						Log.e("TG","Control.Data_ContentAPI:"+Control.Data_ContentAPI);
						JSONObject jsonObj = new JSONObject(Control.Data_ContentAPI);
		
						
						JSONArray jsonarray_cards=jsonObj.getJSONArray("data");
					
						for (int i = 0; i <jsonarray_cards.length(); i++)
						{

							try {
							JSONObject jsonObj_cards=jsonarray_cards.getJSONObject(i);
							JSONArray jsonarray_card=jsonObj_cards.getJSONArray("card");
							
							
							if(jsonObj_cards.getString("block_id").toString().equals(Control.block_id))
							{
								
								
								
								for (int i2 = 0; i2 <jsonarray_card.length(); i2++)
								{
								   JSONObject jsonObj_card=jsonarray_card.getJSONObject(i2);
									map = new HashMap<String, Object>();
									
									
									try {map.put("card_id", jsonObj_card.getString("card_id").toString());} catch (Exception e) {e.printStackTrace();}
										
									try {map.put("name", jsonObj_card.getString("name").toString());} catch (Exception e) {e.printStackTrace();}
									try {map.put("name2",jsonObj_card.getString("name2").toString());} catch (Exception e) {e.printStackTrace();}
									try {map.put("img",jsonObj_card.getString("img").toString());} catch (Exception e) {e.printStackTrace();}
									try {map.put("card_desc",jsonObj_card.getString("card_desc").toString());} catch (Exception e) {e.printStackTrace();}
									try {map.put("rating1",jsonObj_card.getString("rating1").toString());} catch (Exception e) {e.printStackTrace();}
									try {map.put("rating2",jsonObj_card.getString("rating2").toString());} catch (Exception e) {e.printStackTrace();}
									try {map.put("rating3",jsonObj_card.getString("rating3").toString());} catch (Exception e) {e.printStackTrace();}
									try {map.put("rating4",jsonObj_card.getString("rating4").toString());} catch (Exception e) {e.printStackTrace();}
									
									
									int sum=0;
									try { sum=(Integer.parseInt(jsonObj_card.getString("rating1"))+Integer.parseInt(jsonObj_card.getString("rating2"))+Integer.parseInt(jsonObj_card.getString("rating3"))+Integer.parseInt(jsonObj_card.getString("rating4")))/4;} catch (Exception e) {};
									try { map.put("rating5",""+sum);} catch (Exception e) {map.put("rating5","0");};

									
									
									
									//add new tag
									try {map.put("sponsortype",jsonObj_card.getBoolean("sponsortype"));} catch (Exception e) {e.printStackTrace();}
									try {map.put("cardtype",jsonObj_card.getString("cardtype").toString());} catch (Exception e) {e.printStackTrace();}
									try {map.put("tel",jsonObj_card.getString("tel").toString());} catch (Exception e) {e.printStackTrace();}
									try {map.put("web",jsonObj_card.getString("web").toString());} catch (Exception e) {e.printStackTrace();}
									try {map.put("latitude",jsonObj_card.getString("latitude").toString());} catch (Exception e) {e.printStackTrace();}
									try {map.put("longitude",jsonObj_card.getString("longitude").toString());} catch (Exception e) {e.printStackTrace();}

//									Log.e("TG","name"+Double.parseDouble(jsonObj_card.getString("latitude").toString()));
//
//									Log.e("TG","latitude"+Double.parseDouble(jsonObj_card.getString("latitude").toString()));
//									Log.e("TG","longitude"+Double.parseDouble(jsonObj_card.getString("longitude").toString()));
//	
								
									//tel
									//web
									//latitude
									//longitude
									
									
									Log.e("tg", "img="+jsonObj_card.getString("img").toString());
									
									
									Control.Cardlist_ShowDetail.add(false);
									MyArrList.add(map);
									 adapter.notifyDataSetChanged();   
								}
							}
		
							} catch (Exception e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}
							
							
						}
		
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
				  }
			}); // end of runOnUiThread
			
				 
			return null;
		}

		@Override
		protected void onPreExecute() {

			
			progressBar1=(ProgressBar)findViewById(R.id.progressBar1);
			progressBar1.setVisibility(View.VISIBLE);
			
			
			Log.e("tg", "onPreExecute()");
			Control.Cardlist_ShowDetail.clear();
			adapter=null;
			
			if (adapter == null) {
				adapter = new CardListAdapter(CardActivity.this, MyArrList);
				list_view_card.setAdapter(adapter);
				
			}

			
			super.onPreExecute();
		}

		@Override
		public void onProgressUpdate(Integer... progress) {

			Log.e("star", "progressupdate");
			
			
		}

		@Override
		protected void onPostExecute(Object result) {
			
		 if(!onCancelled) 
		 
		 {
			 progressBar1.setVisibility(View.INVISIBLE);
//			 try{
//				
//						runOnUiThread (new Thread(new Runnable() { 
//					         public void run() {
//					        	 
//					        	 runOnUiThread (new Thread(new Runnable() { 
//							         public void run() {
//					                adapter.notifyDataSetChanged();   
//					               
//							         }
//							     }));
//					         }
//					     }));
//			 } catch (Exception ex){ Log.e("LISTVIEW",ex.toString()); }
		 }
			
		}

	}

	

	
	
}
